package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbGoodsClassification;
import com.ruoyi.system.service.ITbGoodsClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品分类Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/classification")
public class TbGoodsClassificationController extends BaseController
{
    @Autowired
    private ITbGoodsClassificationService tbGoodsClassificationService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:classification:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbGoodsClassification tbGoodsClassification)
    {
        startPage();
        List<TbGoodsClassification> list = tbGoodsClassificationService.selectTbGoodsClassificationList(tbGoodsClassification);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:classification:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGoodsClassification tbGoodsClassification)
    {
        List<TbGoodsClassification> list = tbGoodsClassificationService.selectTbGoodsClassificationList(tbGoodsClassification);
        ExcelUtil<TbGoodsClassification> util = new ExcelUtil<TbGoodsClassification>(TbGoodsClassification.class);
        util.exportExcel(response, list, "商品分类数据");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:classification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbGoodsClassificationService.selectTbGoodsClassificationById(id));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:classification:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGoodsClassification tbGoodsClassification)
    {
        return toAjax(tbGoodsClassificationService.insertTbGoodsClassification(tbGoodsClassification));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:classification:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGoodsClassification tbGoodsClassification)
    {
        return toAjax(tbGoodsClassificationService.updateTbGoodsClassification(tbGoodsClassification));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('system:classification:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbGoodsClassificationService.deleteTbGoodsClassificationByIds(ids));
    }
}
